let isShow = true;

function show() {
    isShow = true;
    updateOptionMenu();
}

function hide() {
    isShow = false;
    updateOptionMenu();
}

function updateOptionMenu() {
    if (!window.WeixinJSBridge) {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
}

function onBridgeReady() {
    const command = isShow ? 'showOptionMenu' : 'hideOptionMenu';
    window.WeixinJSBridge.call(command);
}

export default {
    show,
    hide,
}